﻿using ConfExpert.Forms.Base;
using DevTeam;
using System;
using System.Windows.Forms;

namespace ConfExpert.Forms.Espresso
{
    public partial class EspTracking : XForm
    {
        string Tip = "E";
        public EspTracking(string _Tip)
        {
            InitializeComponent();
            Tip = _Tip;
            if (Tip == "E")
                this.Text = "EspTracking";
            else if (Tip == "EP")
                this.Text = "EspPlusTracking";
            else if (Tip == "K")
                this.Text = "KarbelTracking";
            else if (Tip == "E2016")
                this.Text = "PreEspresso2016";
            else if (Tip == "PR")
                this.Text = "SS17PrintCollection";

            TAM.EspTrackingTableAdapter = new Datasets.MyDataTableAdapters.EspTrackingTableAdapter();
        }

        BindingSource bs;
        private void EspTracking_Load(object sender, EventArgs e)
        {
            
            bs = new BindingSource(ds, "EspTracking");
            AddBsToList(bs);
            InitGridView(gv, bs);
            gv.AddSummary();
            gv.SetCaptions("BREG:B.REG", "BPL:B.PL", "SLYC:S.LYC");

            if (Tip == "PR")
                gv.MakeColumnInvisible("BREG", "GR7", "BPL", "SLYC", "TRM", "OP", "SEL","EXC","LNN","PP","BYN");

            gv.MakeColumnVisible("InsertedOn");

            foreach (string str in "StokSeti,BREG,GR7,BPL,SLYC,TRM,OP,SEL,EXC,LNN,PP,BYN".Split(",".ToCharArray()))
                gv.Columns[str].Visible = (Tip == "K");

            gv.AddSummary("StokSeti", "BREG", "GR7", "BPL", "SLYC", "TRM", "OP", "SEL", "EXC", "LNN", "PP", "BYN");
            gv.Columns["EspressoBook"].Visible = gv.Columns["Booklets"].Visible = gv.Columns["Pages"].Visible = (Tip == "E" || Tip == "EP" || Tip == "E2016");
            gv.Columns["Tip"].Visible = false;

            GetDetails("EspTracking", "GetTracking", Tip);
            gv.BestFitColumns();

            btnKaydet.ItemClick += btnKaydet_ItemClick;
            gv.OptionsView.NewItemRowPosition = DevExpress.XtraGrid.Views.Grid.NewItemRowPosition.Bottom;
        }

        void btnKaydet_ItemClick(object sender, DevExpress.XtraBars.ItemClickEventArgs e)
        {
            Save();
        }

        private void gv_InitNewRow(object sender, DevExpress.XtraGrid.Views.Grid.InitNewRowEventArgs e)
        {
            gv.GetDataRow(e.RowHandle)["Tip"] = Tip;
        }
    }
}